/*
 * 作者：姚俊
 * 功能：从服务器下载文件的action
 * 日期：2015-05-24
 */
package admin.action.fruits;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.*;

@SuppressWarnings("serial")
public class FruitsFileDownloadAction
	extends ActionSupport
{
	private String inputPath;
	private String contentDisposition;

	public String getInputPath() {
		return inputPath;
	}

	public void setInputPath(String inputPath) {
		this.inputPath = inputPath;
	}
	
	public String getContentDisposition() {
		return contentDisposition;
	}

	public void setContentDisposition(String contentDisposition) {
		this.contentDisposition = contentDisposition;
	}

	public InputStream getTargetFile() throws Exception
	{

		//解决a标签的中文乱码问题
		try {
			this.setInputPath(new String(this.getInputPath().getBytes("iso-8859-1"),"utf-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		//定义名称按照时间戳来命名
		this.setContentDisposition(String.valueOf(System.currentTimeMillis())+".rar");
		System.out.println("现在的路径为:"+this.getInputPath());
		return ServletActionContext.getServletContext()
			.getResourceAsStream("\\upload\\"+this.getInputPath());

	}
}
